package com.wink.charity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;

import com.google.gson.Gson;
import com.storage.memory.FakeData;
import com.wink.common.Identity;


@XmlRootElement(name = "charitylist")
public class CharityList {
	@XmlElementRef
	ArrayList<Charity> data;

	/**
	 * must have
	 */
	public CharityList() {
	}

	public CharityList(ArrayList<Charity> data) {
		this.data = data;
	}

	public ArrayList<Charity> getList() {
		return data;
	}

	public void setData(ArrayList<Charity> data) {
		this.data = data;
	}
	
	public static String toJson(CharityList charitylist) {
		Gson gson = new Gson();
		String json = gson.toJson(charitylist, CharityList.class);
		System.out.println("---> ChairtyList: json  " + json);
		return json;
	}
	
	public static CharityList fromJson(String json) {
		Gson gson = new Gson();
		CharityList retCh = gson.fromJson(json, CharityList.class);
		System.out.println("---> CharityList: fromJson  " + retCh.toString());
		return retCh;
	}
	
	public static void main(String[] args) {
		ArrayList<Charity> list = new ArrayList<Charity>();

		Charity b = new Charity();
		b.setName("Charity1");		
			Identity identity = new Identity();
			identity.setFromCommunity("ABPM");
			identity.setFromUser("PKR");
			identity.setDate(new Date());		
		b.setIdentity(identity);		
		b.setDescription("Sample Charity 1 created for demonstration");		
		list.add(b);
		
		b = new Charity();
		b.setName("Charity2");		
			Identity identity2 = new Identity();
			identity2.setFromCommunity("ABPM");
			identity2.setFromUser("MS");
			identity2.setDate(new Date());		
		b.setIdentity(identity2);		
		b.setDescription("Sample Charity 2 created for demonstration");		
		list.add(b);
		
		CharityList cList = new CharityList();
		cList.setData(list);
		
		String j = new CharityList().toJson(cList);
	}
}
